package com.xyw.his00.controller;

import com.xyw.his00.anno.OptionLog;

import com.xyw.his00.dto.InspectionRequestDTO;
import com.xyw.his00.entity.ResponseData;

import com.xyw.his00.mapper.InspectionRequestMapper;
import com.xyw.his00.pojo.dbpojo.InspectionRequest;
import com.xyw.his00.vo.I_pay;
import com.xyw.his00.vo.PatientInspection;
import jakarta.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/inspectionRequest")
@RestController
public class InspectionRequestController {
    @Resource
    private InspectionRequestMapper inspectionRequestMapper;
    //新增检查申请
    @Transactional
    @OptionLog
    @PostMapping("insertInspectionRequest")
    public ResponseData insertInspectionRequest(
            @RequestBody InspectionRequestDTO[] inspectionRequests
    ) {
        System.out.println("批量插入检查申请执行成功");
        if (inspectionRequests.length == 0) {
            return ResponseData.FAIL;
        } else {
            InspectionRequest[] inspections = InspectionRequestDTO.revert(inspectionRequests);
            for (int i = 0; i < inspections.length; i++) {
                inspectionRequestMapper.insert(inspections[i]);
            }
            return  ResponseData.SUCCESS;
        }
    }
    //搜索未交费的检验申请项目
    @RequestMapping("selectInspectionsNotPay")
    public List<I_pay> selectInspectionsNotPay(int registerId){
        return  inspectionRequestMapper.selectInspectionsNotPay("已开立",registerId);
    }
    //搜索患者检验项目信息
    @RequestMapping("selectPatientInspection")
    public List<PatientInspection> selectPatientInspection(int registerId){
        return inspectionRequestMapper.selectPatientInspection(registerId);
    }
    //根据医生id搜索患者检验项目信息
    @RequestMapping("selectPatientInspectionByDoctorId")
    public List<PatientInspection> selectPatientInspectionByDoctorId(int doctorId){
        return inspectionRequestMapper.selectInspectionRequestByDoctorId(doctorId);
    }
}
